import axios from 'axios'


const API_BASE = 'http://localhost:8080/api/ai'
const API_BASE2='http://localhost:8080/api/questions'
const API_BASE3='http://localhost:8080/api/myquestions'
const API_BASE4='http://localhost:8080/api/aiEssay'
const API_BASE5='http://localhost:8080/api/Search'
export const generateQuestions = async (num, questionclass) => {
  const response = await axios.post(`${API_BASE}/questions`, null, {
    params: { num, questionclass }
  })
  return response.data
}
export const generateAnswerQuestions = async (num, questionclass) => {
  const response = await axios.post(`${API_BASE}/answerquestions`, null, {
    params: { num, questionclass }
  })
  return response.data
}
export const Wchoixequestion = async (allwrong) => {
  const response = await axios.post(`${API_BASE2}/insertChoiceQuestion`, allwrong
  
  )
  return response.data
}
export const insertAnswerQuestion = async (wronganswerquestion) => {
  const response = await axios.post(`${API_BASE2}/insertAnswerQuestion`, wronganswerquestion
  
  )
  return response.data
}
export const insertmychoicequestion = async (wcqQuestions) => {
  const response = await axios.post(`${API_BASE2}/insertmychoicequestion`, wcqQuestions
  
  )
  return response.data
}
export const getscores = async (answerquestion) => {
  const response = await axios.post(`${API_BASE}/getscore`, answerquestion
  
  )
  return response.data
}
export const insertWAnswerQuestions = async (wronganswerquestions) => {
  const response = await axios.post(`${API_BASE2}/insertWAnswerQuestions`, wronganswerquestions
  
  )
  return response.data
}
export const choiceQ = async (user_id: string, status: number) => {
  const response = await axios.get(`${API_BASE3}/choiceQ`, {
    params: {  
      user_id,
      status
    }
  })
  return response.data
}
export const answerQ = async (user_id: string, status: number) => {
  const response = await axios.get(`${API_BASE3}/answerQ`, {
     params: { 
      user_id,
      status
    }
    }
  
  )
  return response.data
}
export const deleteMyWAnswerQ = async (id: number) => {
  const response = await axios.delete(`${API_BASE3}/deleteMyWAnswerQ`, {
    params: {  
      id
    }
  })
  return response.data
}
export const deleteMyWChoiceQ = async (id: number) => {
  try {
    const response = await axios.delete(`${API_BASE3}/deleteMyWChoiceQ`, {
      params: { id }  
    })
    return response.data
  } catch (error) {
    console.error('删除失败:', error)
    throw error
  }
}
export const generateSimplify = async (essay: string) => {
  const response = await axios.post(`${API_BASE4}/generateSimplify`, { essay });
  return response.data.data; // 只返回简化结果
};
export const findpromptC = async (user_id: string, status: number) => {
  const response = await axios.get(`${API_BASE5}/findpromptC`, { 
    params: { 
      user_id,
      status
    }
    }
  )
  return response.data}
  export const findpromptA = async (user_id: string, status: number) => {
  const response = await axios.get(`${API_BASE5}/findpromptA`, { 
    params: { 
      user_id,
      status
    }
    }
  )
  return response.data}
   export const findanswerquestionprompt = async (prompt:String) => {
  const response = await axios.get(`${API_BASE5}/findanswerquestionprompt`, { 
    params: {  
      prompt
    }
    }
  )
  return response.data}
   export const findchoicequestionprompt = async (prompt:String) => {
  const response = await axios.get(`${API_BASE5}/findchoicequestionprompt`, { 
    params: {  
      prompt
    }
    }
  )
  return response.data}
  
  
